<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<%@ include file="../../header_inc.jsp"%>
<style type="text/css">
#cenTitle input{
	margin-left:20px;
	margin-top:7px;
	background: url('tree_icons.png') no-repeat -208px -18px;

}
</style>
<script type="text/javascript">
	//所有的子窗体都需要有一个save函数，当点击弹出窗体的保存按钮时所进行的操作

	function btnSave_click() {
			var fun_ret;
			
			 var nodeSelect = $('#treeModule').tree('getChecked');
		        var ids=",";
		        for(var i=0;i<nodeSelect.length;i++){
		            var pnode =  $('#treeModule').tree('getParent',nodeSelect[i].target);
		            if(pnode != null)
		            {
		                var pid = pnode.id;
		                if(ids.indexOf(","+pid+",") < 0)
		                {
		                    ids = ids + pid + ",";
		                }
		                var ppnode =  $('#treeModule').tree('getParent',pnode.target);
		                if(ppnode != null)
		                {
		                    var ppid = ppnode.id;
		                    if(ids.indexOf(","+ppid+",") < 0)
		                    {
		                        ids = ids + ppid + ",";
		                    }
		                }
		            }
		            ids = ids + nodeSelect[i].id + ",";
		        }
		        $('#mids').val(ids);
			
			
			
			var vals = $('#formModule').serialize();
			var url = '${saveUrl}';
			$.ajax({
				async : false,
				type : "POST",
				url : url,
				data : vals,
				cache : false,
				dataType : 'json',
				success : function(data) {
					if (data.success != 0) {
						//top.Ext.Msg.alert("提示",data.msg);
						Ext.Msg.alert("提示", data.msg);
					} else {
						fun_ret = true;
					}
				}
			});
	return fun_ret;
	}
	
	 $(document).ready(function(){
			//获取当前用户可查看到的部门
			showDataInCombotree('${ctx }/manage/sysDepartment/getAllDepaetment?flag=0',$("#depId"),'${model.sysDepartment.depId}');
		 
	 $('#treeModule').tree({onLoadSuccess:function(){
		 var s = "${model.roleMenus }";
		 console.log(s);
		var str= new Array();
     	str=s.split(",");
     	console.log(str);
     	
     	  $.each(str,function(){
              var node = $('#treeModule').tree('find', this);//查找节点  
              if(node != null)
              {
                  var sub =  $('#treeModule').tree('getChildren',node.target);
                  if(sub.length == 0)
                  {
                      $('#treeModule').tree('check', node.target);//将得到的节点选中 
                  }
                  
              }
                  
              
          });
		 
	   }});
	 });
		
	//将节点全部选中
	    function treeChecked(selected, treeMenu) {
			var roots = $('#' + treeMenu).tree('getRoots');//返回tree的所有根节点数组  
			if (selected.checked) {
				for (var i = 0; i < roots.length; i++) {
					var node = $('#' + treeMenu).tree('find', roots[i].id);//查找节点  
					$('#' + treeMenu).tree('check', node.target);//将得到的节点选中  
				}
			} else {
				for (var i = 0; i < roots.length; i++) {
					var node = $('#' + treeMenu).tree('find', roots[i].id);
					$('#' + treeMenu).tree('uncheck', node.target);
				}
			}
		}
	
</script>
</head>
<body>
	<div style="padding: 1px" align="center">
	
		<form id="formModule" method="post">
			<table border="0">
			<tr height="0">
					<td><c:if test="${!empty model.createTime }"><input type="hidden" value="${model.createTime }" name="createTime"></input></c:if></td>
				</tr>
				<tr height="0">
					<td><c:if test="${!empty model.id }"><input type="hidden" value="${model.id }" name="id"></input></c:if></td>
				</tr>
				<tr height="30">
					<td>角色名称：</td>
					<td><input id="roleName" maxlength="10" 
						class="easyui-validatebox textbox" type="text"
						name="roleName" data-options="required:true"
						style="width: 180px;height: 25px" value="${model.roleName }"></input></td>
				</tr>
				<tr height="30">
					<td>说明：</td>
					<td><textarea id="remark" maxlength="30" 
						class="easyui-validatebox textbox" type="text" 
						name="remark" data-options="required:true"
						style="width: 180px" >${model.remark }</textarea></td>
				</tr>
		
				<tr height="30">
					<td>所属单位：</td>
                    <td><select id="depId" name="sysDepartment.depId" class="easyui-combotree" style="width: 180px;height: 25px" data-options="required:true,editable:false"></select>
                    </td>
				</tr>
				<tr>
					<td>状态：</td>
					<td><select id="status" name="status">
							<option value="9" <c:if test="${model.status== 9 }">selected</c:if>>正常</option>
							<option value="0" <c:if test="${model.status== 0 }">selected</c:if>>禁用</option>
					</select></td>
				</tr>
			</table>
	
    		
    		<p id="pLimits" style="position:absolute; left:25px; top:125px">选择权限:</p>

			<div style="overflow:scroll; position:absolute;left:85px;top:135px;width:205px;height:260px">
			   <ul  style="position:absolute;width:205px;height:175px">
					<div id="cenTitle" data-options="region:'center',title:''" fit="true">
           				<div class="easyui-panel" style="padding:0px" style="height:400px" >
        					<input type="checkbox" onClick="treeChecked(this,'treeModule')" />全选
                			<ul id="treeModule"  class="easyui-tree" data-options="url:'${ctxl}/manage/sysMenus/getPermissModule?type=3',method:'get',animate:true,checkbox:true" idField="id" treeField="text"></ul>
       	 				</div>
               		 <input id="mids" type="hidden" name="roleMenus"> 
      				</div>
				</ul>
			</div>
		</form>
		
		 
      	 
	</div>
</body>
</html>
